/*
 * jornada720.c: Jornada 720 with flash board specific stuff
 *
 * Copyright (C) 2001  Hewlett-Packard Company
 * Written by Christopher Hoover <ch@hpl.hp.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ident "$Id: jornada720.c,v 1.3 2002/01/03 16:07:18 erikm Exp $"

#ifdef HAVE_CONFIG_H
# include <blob/config.h>
#endif

#include <blob/flash.h>
#include <blob/init.h>
#include <blob/sa1100.h>
#include <blob/serial.h>
#include <blob/time.h>

/* flash descriptor for Jornada720 flash */

/* 2 x Intel 28F128J3A StrataFlash (16 MB) [32MB total] */
/* http://developer.intel.com/design/flcomp/datashts/29066709.pdf */
static flash_descriptor_t jornada720_flash_descriptors[] =
{
	{
		/* One hundred twenty eight 128KB blocks */
		size: 2 * 128 * 1024,
		num: 128,
		lockable: 1
	},
	{
		/* NULL block */
	},
};


static int jornada720_enable_vpp(void)
{
	PPSR |= GPIO_GPIO7;
	PPDR |= GPIO_GPIO7;

	return 0;
}

static int jornada720_disable_vpp(void)
{
	PPSR &= ~GPIO_GPIO7;

	return 0;
}


static void init_flash_driver(void)
{
	flash_descriptors = jornada720_flash_descriptors;

	flash_driver = &intel32_flash_driver;
	flash_driver->enable_vpp = jornada720_enable_vpp;
	flash_driver->disable_vpp = jornada720_disable_vpp;
}

__initlist(init_flash_driver, INIT_LEVEL_DRIVER_SELECTION);


static void init_hardware(void)
{
	PPSR &= ~(GPIO_GPIO10 | GPIO_GPIO7);
	PPDR |= (GPIO_GPIO10 | GPIO_GPIO7);

#warning "Please check this code!"
	/* Careful over here! the timer might not yet be initialised
	 * at this point, so calling msleep() is unsafe! The best way
	 * to make sure that it is, is to put the GPIO stuff in a
	 * separate init function that runs at
	 * INIT_LEVEL_INITIAL_HARDWARE+1. The serial port stuff can be
	 * called without problems at INIT_LEVEL_INITIAL_HARDWARE -- Erik
	 */
	msleep(10 * 1000);

	/* Take the MCU out of reset mode */
	PPSR |= GPIO_GPIO10;

	/* select serial driver */
	serial_driver = &sa11x0_serial_driver;
}

__initlist(init_hardware, INIT_LEVEL_DRIVER_SELECTION);
